package gatech.cs2340.adventuretime.persistent;

import gatech.cs2340.adventuretime.persistent.Appointment;
import gatech.cs2340.adventuretime.persistent.Invoice;
import gatech.cs2340.adventuretime.persistent.Record;
import gatech.cs2340.adventuretime.persistent.TreatmentRecord;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class Patient extends User {
	

	/**
	 * a record of all times the doctor has seen this patient.
	 * stores time-dependent information like weight
	 */
	private HashMap<Date,TreatmentRecord> treatmentRecords;
	
	/**
	 * Stores the most recent treatment to facilitate retreival from treatmentRecords
	 */
	private Date mostRecentTreatment;
	
	
	/**
	 * Only allowing users to be created strictly with a name and password, for db stability
	 * We don't provide a default constructor for this purpose.
	 * @param username for all users
	 * @param password for all users
	 */
	public Patient(String username, String password) {
		super(username, password);
		treatmentRecords = new HashMap<Date,TreatmentRecord>();
		mostRecentTreatment = null;
		
		// TODO initialize patient's instance vars
	}
	
	private Patient() {
		super();
		treatmentRecords = null;
		mostRecentTreatment = null;
	}
	
	/** 
	 * create a prototype of the patient to be used for querying the database
	 * @param name
	 * @param creationDate
	 * @param username
	 * @param password
	 * @return
	 * 		A patient prototype
	 */
	public Patient createPatientPrototype(String name, Date creationDate, String username, String password) {
		Patient prototype = new Patient();
		prototype.setName(name);
		prototype.setCreationDate(creationDate);
		prototype.setUsername(username);
		prototype.setPassword(password);
		return prototype;
	}
	
	
	public void addTreatmentRecord(TreatmentRecord tr) {
		treatmentRecords.put(tr.getDate(),tr);
		if(mostRecentTreatment == null || mostRecentTreatment.before(tr.getDate())) {
			mostRecentTreatment = tr.getDate();
		}
	}
	
	/**
	 * generate a cool graph of the patient's weight with this
	 * @return hashmap of the weight/dates.
	 */
	public HashMap<Date, Integer> getWeightHistory() {
		HashMap<Date, Integer> weightHist = new HashMap<Date, Integer>();
		for(TreatmentRecord tr : this.treatmentRecords.values()) {
			if(tr.getWeight() > 0) {
				weightHist.put(tr.getDate(), tr.getWeight());
			}			
		}
		return weightHist;
	}

	/**
	 * Gets the most current weight of the patient
	 * @return the current weight of the patient
	 */
	public int getWeight() {
		return (this.treatmentRecords.size() > 0) ? this.treatmentRecords.get(0).getWeight() : -1;
	}
	
	


	
	
	

}
